package com.yanqu.road.server.cmd.activity.eggs;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.eggs.EggsActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.eggs.EggsActivityModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_EGGS_TEST_ANWSER, desc = "问答题回答")
public class EggsTestAnswerCmd extends AbstractCommand {
    private int activityId;
    private int choose;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        EggsActivityProto.EggsTestReqMsg reqMsg = EggsActivityProto.EggsTestReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        choose = reqMsg.getChoose();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!SystemOpenMgr.systemOpen(player, eSystemId.EggsActivity.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        ret = player.getModule(EggsActivityModule.class).testAnswer(activityId, choose);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(0 != ret){
            EggsActivityProto.EggsTestRespMsg.Builder respMsg = EggsActivityProto.EggsTestRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_EGGS_TEST_ANWSER, respMsg);
        }
    }
}
